package chapter5.homework.GeometryCalc;

import java.util.InputMismatchException;
import java.util.Scanner;

class Triangle {
    public static int getCounter() {
        return counter;
    }

    static int counter;
    double a;
    double b;

    public double getA() {return a;}
    public double getB() {return b;}
    public double getC() { return c;}
    public void setA(double a) {
        this.a = a;
    }
    public void setB(double b) {this.b = b;}
    public void setC(double c) {
        this.c = c;
    }


    double c;
    boolean calc(){
        Scanner scanner=new Scanner(System.in);
        int s=0;
        while (true){
            try {
                System.out.println("请输入第" + ++s + "条边的长度");
                this.setA(scanner.nextDouble());
                System.out.println("请输入第" + ++s + "条边的长度");
                this.setB(scanner.nextDouble());
                System.out.println("请输入第" + ++s + "条边的长度");
                this.setC(scanner.nextDouble());
                if (test(this)) {
                    showResult();
                    count();
                    return true;
                } else {
                    System.out.println("输入长度无效，请再输一次");

                }
            }
            catch (InputMismatchException ime) {
                System.out.println("请输入数字！");
            }
        }
    }
    static void count() {

        counter++;
    }
    static boolean test(Triangle t) {
        if (t.a<=0) return false;
        else if (t.b<=0) return false;
        else if (t.c<=0) return false;
        else if (t.a > t.b + t.c) return false;
        else if (t.b > t.a + t.c) return false;
        else if (t.c > t.a + t.b) return false;
        else return true;
    }
    double S(){
        double p=(this.a+this.b+this.c)/2;
        return Math.sqrt(p*(p-this.a)*(p-this.b)*(p-this.c));
    }
    double C(){
        return this.a+this.b+ this.c;
    }
    void showResult(){
        System.out.println("该三角形周长：\t"+this.C());
        System.out.println("面积：\t\t"+this.S());
    }

}
